package com.qin.mall.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.mall.domain.OmsOrderReturnApply;
import com.qin.mall.dto.OmsUpdateStatusParam;
import com.qin.mall.dto.OmsOrderReturnApplyResult;
import com.qin.mall.dto.OmsReturnApplyQueryParam;
import com.qin.mall.service.OmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单退货申请管理
 * @author Leisure
 * create 2022 2022/11/10 14:37
 **/
@RestController
@RequestMapping("/return")
public class OmsOrderReturnApplyController {
    
    @Autowired
    private OmsOrderReturnApplyService orderReturnApplyService;

    /**
     * 分页条件查询申请
     * @param pageNum
     * @param pageSize
     * @param queryParam
     * @return
     */
    @PostMapping("/list")
    public CommonResult<MyBatisPlusPage<OmsOrderReturnApply>> list(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                                                   @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize,
                                                                   @RequestBody OmsReturnApplyQueryParam queryParam){
        Page<OmsOrderReturnApply> list = orderReturnApplyService.list(queryParam, pageNum, pageSize);
        return CommonResult.success(MyBatisPlusPage.mpPage(list));
    }

    /**
     * 批量删除申请
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids){
        int count = orderReturnApplyService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     * 修改申请状态
     * @param id
     * @param statusParam
     * @return
     */
    @PostMapping("/update/status/{id}")
    @ResponseBody
    public CommonResult updateStatus(@PathVariable Long id,
                               @RequestBody OmsUpdateStatusParam statusParam){
        int count = orderReturnApplyService.updateStatus(id, statusParam);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     * 获取指定申请详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult getItem(@PathVariable Long id){
        OmsOrderReturnApplyResult item = orderReturnApplyService.getItem(id);
        return CommonResult.success(item);

    }
    
    
    
}
